// vote_example
//拼团首页
exports.vote_example  = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    var oa_id = 0;

    //任务流创建
    async.waterfall([
        // 查询最近结束的投票活动
            function (cb) {

                var now = Date.parse(new Date())*0.001;
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_vote_activity_info+"/between/vac_vote_end_time-"+now+"/sort_order/vac_vote_end_time-desc/limit/1",
                        method: 'POST',
                        data: {
                            fields: ["vac_oaid"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        oa_id = data.data[0].vac_oaid;

                        console.log(oa_id);
                        cb();
                    }
                );

            },
        // 查询该投票活动下用户信息
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_vote_join_user_info +"/vau_oaid/40/sort_order/vau_poll-desc/limit/20",
                        method: 'GET'
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }
                        resultData.joinUser = data.data;

                        cb();
                    }
                );

            },

        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}

